﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Windows.Threading;
using System.Threading;

namespace Break
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        ManualResetEvent resetEvent = new ManualResetEvent(false);
        public MainWindow()
        {
            InitializeComponent();
            new Thread(change).Start();
            this.Visibility = Visibility.Visible;
        }
        public void change()
        {
            resetEvent.WaitOne();
            Action hidden = () => { this.Visibility = Visibility.Hidden; };
            Action visible = delegate(){ this.Visibility = Visibility.Visible; };

           while (true)
            {
                if (this.Visibility==Visibility.Visible)
                {
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, hidden);
                    Thread.Sleep(25*60 * 1000);
                    continue;
                }
                else if (this.Visibility == Visibility.Hidden)
                {
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, visible);
                    Thread.Sleep(5*60* 1000);
                    continue;

                }
            }
        }
    

        private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            resetEvent.Set();
        }
    }
}
